import java.util.concurrent.*;

public class Deadcopy implements Runnable {
    public static  final Object o1=new Object();
    public static  final Object o2=new Object();

    private int flat;

    public Deadcopy(int flat) {
        this.flat = flat;
    }

    @Override
    public void run() {
        if(flat==1){
            synchronized (o1){
                try {
                    System.out.println("o1");
                    Thread.sleep(800);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                synchronized (o2){
                    System.out.println("o2");
                }
            }
        }
        if(flat==2){
            synchronized (o2){
                try {
                    System.out.println("o1");
                    Thread.sleep(800);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                synchronized (o1){
                    System.out.println("o2");
                }
            }
        }

    }

    public static void main(String[] args) {
        Deadcopy d1=new Deadcopy(1);
        Deadcopy d2=new Deadcopy(2);
        ExecutorService pool= Executors.newFixedThreadPool(2);
        ExecutorService s=new ThreadPoolExecutor(1,1,0, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new  ThreadPoolExecutor.DiscardOldestPolicy());
        ExecutorService as=Executors.newScheduledThreadPool(1);
                s.execute(d1);
        s.execute(d2);
        s.shutdown();
    }
}
